package com.example.myapplication.ui.home;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.ui.home.entity.Data;

import java.util.List;

public class AdsAdapter extends RecyclerView.Adapter<AdsAdapter.AdsViewHolder> {

    private List<Data> adsList;

    public AdsAdapter(List<Data> adsList) {
        this.adsList = adsList;
    }


    @NonNull
    @Override
    public AdsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        Log.d("打印1","");
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home, parent, false);
        return new AdsViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull AdsViewHolder holder, int position) {
        holder.bindData(adsList.get(position),holder.itemView.getContext());
    }

    @Override
    public int getItemCount() {
        return adsList.size();
    }

    public static class AdsViewHolder extends RecyclerView.ViewHolder {

        private ImageView adImageView;
        private TextView textView;
        private TextView textTitleView;

        public AdsViewHolder(@NonNull View itemView) {
            super(itemView);
            textTitleView = itemView.findViewById(R.id.recycle_view_title);
            textView = itemView.findViewById(R.id.recycle_view_context);
        }

        public void bindData(Data data,
                             Context context) {
//            // 加载广告图片，这里需要使用图片加载库，如Glide或Picasso
//            Glide.with(context)
//                    .load(R.drawable.ic_launcher_background)
//                    .into(adImageView);
            textTitleView.setText(data.getTitleName());
            textTitleView.setTextColor(Color.BLACK);

            textTitleView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View arg0) {
                    //调到拨号界面
                    Log.d("打印1",arg0.toString());
                }

            });
            textView.setText(data.getContent());
        }

    }
}